package com.lw.spring.javademo.submit;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/submit")
public class SubmitServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取表单数据
        String name = request.getParameter("name1");
        String email = request.getParameter("email");

        // 设置响应内容类型
        response.setContentType("text/html");
        // 获取输出流，写入响应数据
        PrintWriter out = response.getWriter();
        out.println("<html><body>");
        out.println("<h1>Form Submission Results</h1>");
        out.println("<p>Name: " + name + "</p>");
        out.println("<p>Email: " + email + "</p>");
        out.println("</body></html>");
    }
}

